package com.photoeditor.demo.ui.widget.image.enlarge;

import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.RectF;

import com.common.base.log.DLog;

/**
 * Created by winn on 17/10/26.
 */

public class EnlargerBean {

    /**
     * 在图片中位置
     **/
    private Rect mRect;

    private float mScale;

    /**
     * 当前是否被选中
     **/
    private boolean mIsSelected;

    private RectF mRectTmp = new RectF();

    public EnlargerBean(Rect rect, float scale) {
        mRect = rect;
        mScale = scale;
        mRectTmp.set(mRect.left, mRect.top, mRect.right, mRect.bottom);
    }

    public Rect getRect() {
        return mRect;
    }

    public void setRect(Rect rect) {
        this.mRect = rect;
    }

    public boolean isIsSelected() {
        return mIsSelected;
    }

    public void setIsSelected(boolean isSelected) {
        this.mIsSelected = isSelected;
    }

    public float getScale() {
        return mScale;
    }

    public void setScale(float scale) {
        this.mScale = scale;
    }

    public void scaleSize(float scale) {
        if (mRect != null) {
            Matrix m = new Matrix();
            m.setScale(scale, scale, mRect.centerX(), mRect.centerY());
            RectF rect = new RectF();
            m.mapRect(rect, mRectTmp);
            mRect.set((int) rect.left, (int) rect.top, (int) rect.right, (int) rect.bottom);
            mRectTmp.set(rect);
        }
    }

    public void move(float dx, float dy) {
        if (mRect != null) {
//            DLog.i("winn", "move " + mRect + " dx:" + dx + "  dy:" + dy);
            mRect.offset((int) dx, (int) dy);
            mRectTmp.set(mRect.left, mRect.top, mRect.right, mRect.bottom);
            DLog.i("winn", "after  mRect:" + mRect);
        }
    }
}
